#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct Person
{
    char name[64];
    age int;
};

typedef struct Person myPerson;


typedef struct Person1{
    char name[64];
    age int
}myPerson1 = {"hhei",22};

// 匿名结构体
struct {

};


void test1(){
    struct Person p= {name:"xiaoxu",age:20};
    myPerson p1 = {name:"xiaoli",age:19};

    myPerson1.name = "xds";
    myPerson1.age = 30;
    

    //堆上
    struct Person * p3 = malloc(sizeof(struct Person));
    strcpy(p3->name,"ass");
    p3->age = 20;
    
}

printArray(struct Person p[], int len){   // struct Person * p
    for(int i=0;i<len;i++){
        printf("%s\t,%d\n", p[i].name,p[i].age);
    }
}

void test2(){
    struct Person p[] = {
        {"aa",20},
        {"bb",40}
    };

    int len = sizeof(p)/sizeof(struct Person);
    printArray(p,len);

    // 堆区
    struct Person * p1 = malloc(sizeof(struct Person)*4);
    for(int k=0;k<4;k++){
        sprintf(p1[i].name, "name_%d", i+1);
        p1[i].age = 18 + i;
    }

    printfArray(p1, len);

    if(p!=NULL){
        free(p);
        p = NULL;
    }

}



void main(){
    test2();
}